import React, { Component } from 'react';

import FightRecord from 'FightRecord';
import querystring from 'querystring';

import atob from 'atob';
// 背景图片的狂高

const defaultProps = {
  record: {
    played_at: '',
    round_title: '',
    room_code: '',
    room_id: '',
    scores: [
      { name: '', avatar: '', score: '', wins: '', finnal_score: '' },
      { name: '', avatar: '', score: '', wins: '', finnal_score: '' },
      { name: '', avatar: '', score: '', wins: '', finnal_score: '' },
      { name: '', avatar: '', score: '', wins: '', finnal_score: '' },
    ],
  },
};

class App extends Component {
  static defaultProps = defaultProps;
  getRecord() {
    try {
      const { location } = this.props;
      if (location.search) {
        const query = querystring.parse(location.search.slice('1'));
        return JSON.parse(decodeURIComponent(atob(query.record)));
      }
    } catch (error) {
      return this.props.record;
    }
  }

  render() {
    const props = this.getRecord();
    return <FightRecord {...props} />;
  }
}

export default App;
